#include using namespace std; void getNumbers(int list[], int numbersToGet ) { for(int i = 0; i < numbersToGet;i++) { cin >> list[i]; } } void removeItemAtIndex(int list[], int index, int& length) { for(int i = index; i < length-1; i++) { list[i] = list[i+1]; } length--; } void displayNumbers(int list[], int length ) { for(int i = 0; i < length; i++) { cout << list[i] << endl; } } void insertItemAtIndex(int list[100], int n, int index, int& gradeCount) { for(int i = gradeCount; i > index; i--) { list[i] = list[i-1]; } list[index] = n; gradeCount++; } void selectionSort(int list[], int length, bool ascending) { for(int i = 0; i < length; i++) { int indexOfSmallest = i; //find where the smallest number is //in the index range i to the end of the list for(int j = i + 1; j < length; j++) { if(ascending) { if(list[j] < list[indexOfSmallest]) { indexOfSmallest = j; } } else { if(list[j] > list[indexOfSmallest]) { indexOfSmallest = j; } } } //swap the element at indexOfSmallest with the element at i int temp = list[i]; list[i] = list[indexOfSmallest]; list[indexOfSmallest] = temp; } } void main() { int grades[100]; int gradeCount; cout << "How many grades do you want to enter? "; cin >> gradeCount; cout << endl; getNumbers(grades, gradeCount); //removeItemAtIndex(grades, 2, gradeCount); //removeDuplicates cout << endl; cout << endl; cout << endl; insertItemAtIndex(grades, 777, 3, gradeCount); selectionSort(grades,gradeCount,true); displayNumbers(grades, gradeCount); }